package com.company.project.service.impl;

import com.company.project.dao.OnlineClassesMapper;
import com.company.project.model.OnlineClasses;
import com.company.project.model.Thesis;
import com.company.project.service.OnlineClassesService;
import com.company.project.core.AbstractService;
import com.company.project.util.PageUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * Created by CodeGenerator on 2018/10/08.
 */
@Service
@Transactional
public class OnlineClassesServiceImpl extends AbstractService<OnlineClasses> implements OnlineClassesService {
    @Resource
    private OnlineClassesMapper onlineClassesMapper;

    //获取课程
    @Override
    public List<OnlineClasses> getOnlineClasses() {
        return onlineClassesMapper.selectOnlineClasses();
    }

    //获取全部课程，分页
    @Override
    public PageUtil<OnlineClasses> getOnlineClassesAll(Integer pageIndex) {
        PageUtil<OnlineClasses> pageUtil = new PageUtil();
        pageUtil.setPageSize(15);
        pageUtil.setCpage(pageIndex);
        pageUtil.setTotalRow(this.getAllCount());
        pageUtil.setLists(onlineClassesMapper.selectAllOnlineClasses(pageUtil));
        return pageUtil;
    }

    //获取课程总条数
    @Override
    public Integer getAllCount() {
        return onlineClassesMapper.selectAllCount();
    }

    /**
     * 删除线上课程
     * @param id
     * @return
     */
    @Override
    public Boolean deleteOC(Integer id) {
        Boolean aBoolean = onlineClassesMapper.deleteOC(id);
        return aBoolean;
    }

    /**
     *添加线上课程
     * @param onlineClasses
     * @return
     */
    @Override
    public Boolean addOnlineClasses(OnlineClasses onlineClasses) {
        return onlineClassesMapper.addOnlineClasses(onlineClasses);
    }

    @Override
    public Boolean updateOnlineClasses(OnlineClasses onlineClasses) {
        return onlineClassesMapper.updateOnlineClasses(onlineClasses);
    }

    /**
     * 修改上架
     * @param onlineClasses
     * @return
     */
    @Override
    public Boolean updateTopOnlineClasses(OnlineClasses onlineClasses) {
        return onlineClassesMapper.updateTopOnlineClasses(onlineClasses);
    }

    /**
     * 根据id查询线上课程详情
     * @param id
     * @return
     */
    @Override
    public OnlineClasses selectOnlineClassesById(Integer id) {
        return onlineClassesMapper.selectOnlineClassesById(id);
    }

    /**
     * 查询课程
     * @return
     */
    @Override
    public PageUtil<OnlineClasses> adminSelect(Integer pageIndex) {
        PageUtil<OnlineClasses> pageUtil = new PageUtil();
        pageUtil.setPageSize(5);
        pageUtil.setCpage(pageIndex);
        pageUtil.setTotalRow(this.selectAdminSelectCount());
        pageUtil.setLists(onlineClassesMapper.adminSelect(pageUtil));
        return pageUtil;
    }

    @Override
    public Integer selectAdminSelectCount() {
        return onlineClassesMapper.selectAdminSelectCount();
    }

    /**
     * 上架
     * @param onlineClasses
     * @return
     */
    @Override
    public Boolean addTopOnlineClasses(OnlineClasses onlineClasses) {
        return onlineClassesMapper.addTopOnlineClasses(onlineClasses);
    }

    /**
     * 线上课程详情
     * @param id
     * @return
     */
    @Override
    public List<OnlineClasses> selectOCParticular(Integer id) {
        return onlineClassesMapper.selectOCParticular(id);
    }
}
